package cn.lonecloud.action.user;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.lonecloud.model.User;
import cn.lonecloud.service.UserService;
import cn.lonecloud.service.impl.UserServiceImpl;

/**
 * 验证登录信息
 * @author lonecloud
 */
@WebServlet("/doLogin")
public class CheckLoginServlet extends HttpServlet {

	UserService userService = new UserServiceImpl();

	/**
	 * 
	 */
	private static final long serialVersionUID = 7157409349817965694L;

	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String username = request.getParameter("username");
		String password = request.getParameter("password");
		User user = userService.checkLogin(username, password);
		if (user != null) {
			request.getSession().setAttribute("user", user);
			response.sendRedirect("main");
		} else {
			response.sendRedirect("index");
		}
	}
}
